package ejbs;

import interfaces.IMaquina;

import java.io.Serializable;
import java.util.List;


import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import beans.Maquina;

@Stateless
public class MaquinaEJB implements IMaquina, Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@PersistenceContext(unitName = "ProjetoChamadaPU")
	private EntityManager em;
	

	@Override
	public void insert(Maquina m) {
		em.persist(m);
	}

	@Override
	public void delete(int id) {
		Maquina m;
		m = em.find(Maquina.class, id);
		em.remove(m);
		
	}

	@Override
	public void update(Maquina m) {
		em.merge(m);		
	}

	@Override
	public Maquina select(int id) {
		Query qr = em.createNamedQuery("Maquina.findByIdmaquina");
		qr.setParameter("idmaquina", id);
		Maquina maquina = (Maquina) qr.getSingleResult();
		
		return maquina;
	}

	@Override
	public List<Maquina> SelectAll() {
		Query p = em.createNamedQuery("Maquina.findAll");
		List l =  p.getResultList();
		return l;
	}




}
